<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%request.setCharacterEncoding("utf-8");%>
<%@ include file="pub/top_list2.jsp"%>   
<%
String names = (String) request.getSession().getAttribute("name");
if(request.getParameter("nicheng")!=null&&request.getParameter("nicheng")!=""){
	String sql = "update member set NickName=? where userid=?";
	Object[] param=new Object[2];
	param[0] =request.getParameter("nicheng"); 
	param[1] =names;
	db.executeUpdate(sql, param);
}

%>
<script type="text/javascript">
function checkLength(obj){
	//console.log(obj.value)
	if(obj.value!=""){
		 var curr = getByteLen(obj.value);
	     if (curr < 5 || curr > 20) {
	    	 alert("您输入的昵称不符合要求");
	 		 document.getElementById('nicheng').value="";
	     } 
	} 
}
function getByteLen(val) {
    var len = 0;
    for (var i = 0; i < val.length; i++) {
        var a = val.charAt(i);
        if (a.match(/[^\x00-\xff]/ig) != null) {
            len += 2;
        }
        else {
            len += 1;
        }
    }
    return len;
}
/* function baocun(){
	String sql = "update member set NickName=? where userid=?";
	Object[] param=new Object[2];
	param[0] =document.getElementById('nicheng').value; 
	param[1] =names;
	db.executeUpdate(sql, params);
}  */
</script>

<body>
	<header class="top-header">
		<a class="icona" href="datum.jsp">
				<img src="images/left.png"/>
			</a>
		<h3>修改昵称</h3>		
	</header>
	
	<div class="contaniner">
		<form action="namechange.jsp" method="post" class="nameform">
			<div class="namechange">
				<img src="images/a-icon01.png"/>
				<input type="text" id="nicheng" name="nicheng" placeholder="请输入您的昵称"  onblur="checkLength(this)"/>
			</div>
			<p>推荐使用中文，5-20个字符</p>
			<input type="submit" value="保存"/>
		</form>
		
	</div>

    
	
</body>
</html>